#include "Ring.hpp"

void *production(void *asg)
{
    RingQueue<int> *q = (RingQueue<int> *)asg;
    while (true)
    {
        sleep(1);
        int data = rand() % 100 + 1;
        q->Push(data);
        std::cout << "生产者->:" << data << std::endl;
    }
}

void *consumption(void *asg)
{
    RingQueue<int> *q = (RingQueue<int> *)asg;
    while (true)
    {
        sleep(2);
        int data;
        q->Pop(data);
        std::cout << "消费者->:" << data << std::endl;
    }
}

int main()
{
    RingQueue<int> *q = new RingQueue<int>();
    srand((unsigned long)time(nullptr));
    pthread_t producer, consumer;
    pthread_create(&producer, nullptr, production, q);
    pthread_create(&consumer, nullptr, consumption, q);
    pthread_join(producer, nullptr);
    pthread_join(consumer, nullptr);
    return 0;
}